package com.tz.online.book.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tz.online.book.service.IBookService;
import com.tz.online.entity.Pageing;
import com.tz.online.util.BeanFactory;

/**
 * 根据图书类型查询图书
 * @author Administrator
 *
 */
@WebServlet(name="viewBookByCate",urlPatterns="/book/viewBookByCate")
public class ViewBookByCateAction extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5143726715476824139L;
	//通过bean工厂，获得service接口对象
	IBookService bs = (IBookService) BeanFactory.getBean("bookService");
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//接收图书类型
		String cateId = req.getParameter("cateId");
		
		//接收分页条件
		String pageNow = req.getParameter("pageNow");
		String pageSize = req.getParameter("pageSize");
		
		//如果没有接收到，给予默认
		pageNow = pageNow==null?"1":pageNow;
		pageSize = pageSize==null?"8":pageSize;
		
		Pageing paging = bs.queryBookByCondition(Integer.parseInt(pageNow), Integer.parseInt(pageSize), cateId);
		req.setAttribute("paging", paging);
		req.getRequestDispatcher("/jsp/book/specials.jsp").forward(req, resp);
	}

}
